Hello everybody and welcome to this solution off our Python standard library assessment quiz.
So this Chris covers all topics of our basic section and if you master the Chris you can be sure that
you will also have no problems with our case study.
The second album challenge and actually then you can skip the whole basic section here.
So the Chris has the 15 questions and of course the that easy questions and also harder more tricky
questions.
And if you do not have all 50 questions correct.
So that's no problem as long as you can follow my solutions and think Okay I understand what the guy
is trying to telling me here actually.
Yeah.
Then in this case you should be best prepared for the case study.
So let's start our Chris
a.m. The first question we have.
Uh two two objects 3 and 7.
And we assign the variable a two three and the variable B to seven.
And if we add a and b Of course we get 10 so no surprise we can add integers and we use python as a
calculator.
So the correct answer is 10
question 2.
So the key message here is that you cannot add a string object with an integer like here in the first
two answers so you can only add a string and string of its concatenated so the two strings and then
we do not have this case here as an answer.
And of course we can add two integers as we have here in this case so printing four plus six gives us
10 so we do not get an error message here
here we create a three copies of the string Hello World and are simply concatenated so the correct answer
is here.
This one
here we have a list of the three elements.
And if we multiply a list in that we have the key message here is and that follows.
So that's no element y's operation.
So actually we do not get multiplied elements like here and then this answer you ever you get um three
maybe by Platt by three six multiplied by three and so on.
But this is not how lists work.
And actually we get to three times the copy off our list concatenate.
So this is all a correct answer here.
Here we have them the same list and all three options and then paste and we have the so-called zero
based indexing saw fear fear a list we are starting at the index position zero.
So the integer 2 has the index position zero and then we have one two three four five and six so consequently
we are of a cat in our slice so kept us at index position 0 1 2.
Was also want to have them three four including so we have the indexed positions two to four including
the.
We have to slice for two to five excluding.
So this is the correct answer here
so end this question to answer is actually a slice for the last two elements.
So elephant and six point two and one does not so he and the first option we slice from minus two until
the very last element.
So alternatively to the zero base and next thing we can also index from minus one minus to minus three
and so on.
So minus two with Elif and until the very last element including So the first answer is correct then
the second answer slices from the fifth element or the element at an exposition 5 0 1 2 3 4 5.
It's elephant until the very last including.
So this answer also slices at the very last elements and only here the last answer It slices only elephant.
So in exposition 6 thus excluding
this question here we have an example of in comparison operators so we have exclamation mark equal.
And this checks if 10 is not equal to 9.
And this is true.
And if we apply not to uh gives us false so false is the correct answer here.
Here we check whether dark in quotation mark is a string.
And yes it's a string.
And further we check whether 10 is greater than 8 and this is also true.
And here we have one logical operator and and we only get a true here if all conditions are true.
So dark is a string and time is greater than 8.
And this is the case so we should get a true here.
Here we have an if statement and at the end of this statement We need a colon.
So here we have a colon and he also and after the statement we have to make and then to define the action
we want to take.
If the condition is correct and and does it automatically if you press enter after the if statement
so he and this answer we do not have an intent here for for the print statement and therefore the only
answer that we have a colon and an intent C at this one
here we want to create a list of square numbers from 1 to 10 including and here we have the range object
in the range object by default starts with 0 and the end value as exclusive.
So this answer would give us some clear numbers from 0 to 9 including And the second key message of
this question here is that also after a false statement or in the for loop we have to make a colon and
an indent and here we do not have an intent so the only correct answer is this one here.
Here we have a list of seven names and we want to create a list a names where all the names beginning
with a name are included and only the names beginning with a.
So the question is here we have three codes.
And the question is how many of these codes do the job and the answer is actually that all three codes
work.
So here in the first code we iterate over the names and the first letter of the name is an A.
We append the name to our names list.
So this works.
And the second code does actually the same chop in a list comprehension so we create here a list and
for each name in the name lists we check if the first letter an A and if it is an A.
We append the name into the list.
So this works this letter and in code 3 it is a somewhat tricky one.
So we first of all sort the names lists so the lists are starting with the names beginning with a.
And then we are introducing a by loop and iterating over all indexed positions starting from an exposition
zero of our list.
And as long as the first letter isn't a We append the name to our lists and we increase the index position
by 1 and check the next name.
So this was actually a quite tricky question and the correct answers is three.
All right.
So here we have a list with integers from 1 to 20 and we want to create a new list that contains all
elements of the list that are divisible by three of us out remainder and all other elements would be
stored in another list.
And and that's another condition here.
So the element 3 must not be in any of the new lists.
So actually 3 is actually divisible by three without remainder but it should not be in our list at all.
Let's have a look at the options here.
So actually the answers are from here on are identical.
So if our element is divisible by three we attended to the list.
Uh and as we appended to the list M however the key message is that first of all we have to check whether
we have the element three in our list so.
If this is the case we have to ignore three.
This the keyboard argument continue.
So here if you come to three in our list.
We just ignore three and go on lists then the next element four.
So this is correct.
And here we do not check if we have three.
So actually I would expect to have and three in our list.
L And here we are checking if we have three in our list.
But if we have three we break.
So we completely break the for loop.
So after the first three elements our iteration stops here.
So the correct answer is um the first one
here we define the function division and we have two arguments of the function A and B and B has an
defined parameter equals 1 and the function returns a divided by B.
So if we call the function by just passing 5 so 5 stands for our argument a and for B we have the default
parameter 1.
If you do not set a concrete parameter by calling our function so we saw tests 5 divided by 1.
So this should be the correct answer.
So here we want to create a function that returns to the sum of randomly generated integers and they
interpret the 1 to 10 and we want to be able to set the size of the randomly generated integers as a
monumental parameter off the function.
So we have here two key messages.
So first of all you want to create random integers in range 1 to 10 and answer 2 and 3 do exactly this
but answer 1 creates the random float in range 0 to 1.
So this is not correct and then Option 2 and 3 we can pass a parameter size.
However if we have a look at the function body so he can answer 3.
We have the concrete size 100.
So even if we change the size and then the function header we always get a size of hundred random integers.
And therefore here.
So number 2 is correct.
So here we are able to define the number of random integers we want to create
all right.
So last question here we have a say it's men and with say it's low we have 700 in 2010 900 say it's
in two thousand eleven and so on and we want to create a line plot to visualize ourselves and we want
to have the Yes on the x axis and the states on the y axis and we have to implement plot live here and
the first answer I guess that's actually a scatter blood another line plot so this is not correct and
here the function party plot we have we have to define as the first argument on the x axis so we have
yes and as the second argument say is so answer 3 is actually the way around and therefore we have to
choose answer to.